#include "StatusBar.h"
#include "../../controller/SignalsBus.h"

#include <QProgressBar>
#include <QLabel>
#include <QHBoxLayout>
StatusBar::StatusBar(QWidget *parent)
    : QWidget{parent}
{
    initComponents();
    setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
}

void StatusBar::initComponents()
{
    const auto lbText = new QLabel(tr("准备就绪"));
    const auto layout = new QHBoxLayout();
    progress = new QProgressBar();
    progress->setRange(0,100);
    progress->setTextVisible(false);
    progress->setVisible(false);

    layout->addWidget(lbText);
    layout->addWidget(progress);

    setLayout(layout);

    connect(SignalsBus::getInstance(),&SignalsBus::switchStatus,[=](int status){
        if(status == 0){
            progress->setVisible(false);
            lbText->setText(tr("准备就绪"));
        }else if(status == 1){
            progress->setVisible(true);
            lbText->setText(tr("当前进度"));
        }else if(status == 2){
            progress->setVisible(false);
            lbText->setText(tr("完成"));
        }
    });

    connect(SignalsBus::getInstance(),&SignalsBus::checkPercent,[=](int progressPercent){
            progress->setValue(progressPercent);
    });
}
